package cn.diancan.util.images;
import java.awt.Image;  
import java.awt.image.BufferedImage;  
import java.io.File;  
import java.io.IOException;  
  
import javax.imageio.ImageIO;  
  
public class ImageResizer {  
  
    /*** 
     * 功能 :调整图片大小 开发：
     * @param srcImgPath 原图片路径 
     * @param distImgPath  转换大小后图片路径 
     * @param width   转换后图片宽度 
     * @param height  转换后图片高度 
     */  
    public static void resizeImage(String srcImgPath, String distImgPath,  
            int width, int height) throws IOException {  
  
        File srcFile = new File(srcImgPath);
        Image srcImg = ImageIO.read(srcFile);
        BufferedImage buffImg = null;
        buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);  
        buffImg.getGraphics().drawImage(srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,  
                0, null);
        ImageIO.write(buffImg, "JPEG", new File(distImgPath));  
  
    }  
    
    
    public static void main(String []args){  
        try {  
            ImageResizer.resizeImage("E:/__26188937__6750670.jpg","E:/4d54ff27d1869fc8649a2200.jpg",100,100);  
        } catch (IOException e) {  
            System.out.println("图片转换出现异常！");
        }  
          
    }  
    
  
} 